home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / mcu / dtmf.arc / DTMF05.ASM < prev    next >
Assembly Source File  |  1990-01-08  |  5KB  |  192 lines

  1. * File: DTMF.ASM
  2. * Driver routines for 68HC05 to produce DTMF tones in software
  3.  
  4. * this version uses a fixed 256 byte sine table, and a fixed 128 us sample time
  5. * this allows operation under interrupt control
  6.  
  7. * hardware requirements: 8 bit DAC on port a of 68HC05
  8. * To use, do a JSR to DTINIT to set up timer
  9. * then do a JSR to location DTMF with the digit in the lower nibble of
  10. * Accumulator A
  11. * digit values: 0-9, 10 = #, 11 = *, 12-15 represent a through d
  12. * A 60 ms tone burst will be generated, followed by 60 ms of silence
  13. * The location TTIME may be altered to change this timing
  14.  
  15.     opt    mul        allow multiply instruction
  16.     asct
  17.  
  18. * define test to be non-zero to create test version
  19.  
  20. test    equ    1
  21.  
  22. * First a few definitions
  23.  
  24. deftt    equ    60        default tone time (60 ms)
  25. dac    equ    $0        DAC output on port a
  26. dacddr    equ    $4        data direction register for port with DAC
  27. portb    equ    1        port b address
  28. ddrb    equ    5        ... and its ddr
  29. ctrhi    equ    $18        timer free running counter
  30. ctrlo    equ    $19
  31. ocrhi    equ    $16        output compare register
  32. ocrlo    equ    $17
  33. tcr    equ    $12        timer control register
  34. ocie    equ    $40        output compare interrupt enable
  35. tsr    equ    $13        timer status register
  36. ocf    equ    6        output compare flag bit position
  37. intcnt    equ    128/2        count to load into output compare
  38.  
  39. row1    equ    23        row intervals
  40. row2    equ    25
  41. row3    equ    28
  42. row4    equ    31
  43.  
  44. col1    equ    40        column intervals
  45. col2    equ    44
  46. col3    equ    48
  47. col4    equ    54
  48.  
  49.     org    $50        RAM scratchpad - move this to fit your system
  50. ttime    rmb    1        tone time in milliseconds
  51. ttctr    rmb    2        time counter
  52. ttsave    rmb    2        save the count value for interdigit pause
  53. ttflag    rmb    1        non zero means generate tones
  54. rowptr    rmb    1        next row sample to load
  55. colptr    rmb    1        ditto for columns
  56. rowint    rmb    1        row interval - added to row counter each sample
  57. colint    rmb    1        ditto for column
  58. sample    rmb    1        temp storage for sample
  59.  
  60.     org    $1000
  61. dtinit    sei            disable interrupts
  62.     ifne    test
  63.     rsp            set default stack
  64.     endc
  65.     lda    #deftt        set up time counter
  66.     sta    ttime
  67.     lda    #$ff        set up ddr - all outputs
  68.     sta    dacddr
  69.     ifne    test
  70.     sta    ddrb        set up port b to flag entry to interrupt
  71.     clr    portb
  72.     endc
  73.     lda    #$80        set dac to halfway point
  74.     sta    dac
  75.     clr    ttflag        no tones please
  76.     lda    #ocie        enable output compare interrupt
  77.     sta    tcr
  78.     lda    ctrhi        freeze counter
  79.     sta    ocrhi
  80.     lda    ctrlo
  81.     add    #intcnt
  82.     bcc    dti1
  83.     inc    ocrhi
  84. dti1    tst    tsr
  85.     sta    ocrlo
  86.     cli
  87.     ifeq    test
  88.     rts            done for now
  89.     endc
  90.     ifne    test
  91.     nop
  92. here    bra    here        endless loop
  93.     endc
  94.  
  95. dtmf    and    #$0f        clear out junk
  96.     tax            get row interval
  97.     lda    rowtab,x
  98.     sta    rowint
  99.     lda    coltab,x    and column
  100.     sta    colint
  101.     clr    rowptr        start at 0
  102.     clr    colptr
  103.     lda    ttime        start tone - set time
  104.     ldx    #250        adjust for # of samples in (ttime) msec
  105.     mul            (125/128) * ttime * 8
  106.     clra            x now contains adjusted sample count
  107.     aslx            multiply by 8 to produce sample count
  108.     rola
  109.     aslx
  110.     rola
  111.     aslx
  112.     rola
  113.     coma
  114.     negx            negate so tisr can increment
  115.     bcs    dtmf05        carry if necessary
  116.     inca
  117. dtmf05    sta    ttctr        put into timer
  118.     stx    ttctr+1
  119.     sta    ttsave        save for pause time
  120.     stx    ttsave+1
  121.     inc    ttflag        start tones
  122. dtmf1    brset    0,ttflag,dtmf1    loop till tone complete
  123.     lda    ttsave        now do pause
  124.     sta    ttctr
  125.     lda    ttsave+1
  126.     sta    ttctr+1
  127.     clr    rowint        do the pause by not moving pointers
  128.     clr    colint
  129.     inc    ttflag        start pause
  130. dtmf2    brset    0,ttflag,dtmf2
  131.     rts            done
  132.  
  133. * timer interrupt service routine
  134. * if ttctr != 0, then output next sample to dac
  135.  
  136. tisr    ifne    test
  137.     bset    0,portb
  138.     endc
  139.     lda    ocrlo        (3) add timer count
  140.     add    #intcnt        (2)
  141.     bcc    tisr2        (3) do carry if needed
  142.     inc    ocrhi        (5)
  143. tisr2    tst    tsr        (4) clear flag
  144.     sta    ocrlo        (4)
  145.     brclr    0,ttflag,tisr1    (5) don't generate tone if flag cleared
  146.     ldx    rowptr        (3) get next row sample
  147.     lda    sine,x        (5)
  148.     sta    sample        (4)
  149.     txa            (2) update pointer
  150.     add    rowint        (3)
  151.     sta    rowptr        (4)
  152.     ldx    colptr        (3) get next col sample
  153.     lda    sine,x        (5)
  154.     asra            (3) divide by 4
  155.     asra            (3) divide by 4
  156.     add    sine,x        (5) now have 1.25 * column sample
  157.     add    sample        (3) add to row sample
  158.     eor    #$80        (2) fix sign bit
  159.     sta    dac        (4) out it goes
  160.     txa            (2) update pointer
  161.     add    colint        (3)
  162.     sta    colptr        (4)
  163.     inc    ttctr+1        (5) increment timer
  164.     bne    tisr1        (3) carry needed?
  165.     inc    ttctr        (5) yes - do it
  166.     bne    tisr1        (3) overflow?
  167.     clr    ttflag            yes - turn off tones
  168. tisr1    ifne    test
  169.     bclr    0,portb
  170.     endc
  171.     rti            (9)
  172. *                (7) interrupt response
  173. *                ===
  174. *                               116 cycles when generating tones
  175. *                total overhead at 2 MHz E clock = 116/256 == 45%
  176.  
  177. coltab    fcb    col2,col1,col2,col3    0,1,2,3
  178.     fcb    col1,col2,col3        4,5,6
  179.     fcb    col1,col2,col3        7,8,9
  180.     fcb    col1,col3        #,*
  181.     fcb    col4,col4,col4,col4    a,b,c,d
  182.  
  183. rowtab    fcb    row4,row1,row1,row1    0,1,2,3
  184.     fcb    row2,row2,row2        4,5,6
  185.     fcb    row3,row3,row3        7,8,9
  186.     fcb    row4,row4        #,*
  187.     fcb    row1,row2,row3,row4    a,b,c,d
  188.  
  189.     include    sine56.asm
  190.  
  191.     end
  192.